﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IESN.Enums;
using System.Configuration;

namespace IESN.Common
{
    public class AppConfiguration
    {
        public static EnumCommType CurrentCommType
        {
            get
            {
                var aCommonType = ConfigurationManager.AppSettings["CommType"];
                if (aCommonType == "232")
                {
                    return EnumCommType.Comm;
                }
                else if (aCommonType == "1")
                {
                    return EnumCommType.SysmacAx;
                }
                else
                {
                    return EnumCommType.Simen;
                }
            }
        }

        public static short LinkAddr
        {
            get 
            { 
                short aLinkAddr = 0;
                short.TryParse(ConfigurationManager.AppSettings["LinkAddr"], out aLinkAddr);
                return aLinkAddr;
            }
        }

        public static short PortNum
        {
            get
            {
                short aPortNum = 0;
                short.TryParse(ConfigurationManager.AppSettings["PortNum"], out aPortNum);
                return aPortNum;
            }
        }

        public static int BaudRate
        {
            get
            {
                short aBaudRate = 0;
                short.TryParse(ConfigurationManager.AppSettings["BaudRate"], out aBaudRate);
                return aBaudRate;
            }
        }

        public static short TimeOut
        {
            get
            {
                short aTimeOut = 0;
                short.TryParse(ConfigurationManager.AppSettings["TimeOut"], out aTimeOut);
                return aTimeOut;
            }
        }

        public static short EtNodeAddr
        {
            get
            {
                short aEetNodeAddr = 0;
                short.TryParse(ConfigurationManager.AppSettings["etNodeAddr"], out aEetNodeAddr);
                return aEetNodeAddr;
            }
        }

        public static short EtUnitAddr
        {
            get
            {
                short aEtUnitAddr = 0;
                short.TryParse(ConfigurationManager.AppSettings["etUnitAddr"], out aEtUnitAddr);
                return aEtUnitAddr;
            }
        }

        public static string AdrTable
        {
            get
            {
                return ConfigurationManager.AppSettings["adr_table"];
            }
        }
    }
}
